/*
	This file is part of PropExtractor.

	PropExtractor is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	PropExtractor is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with PropExtractor. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _PEALICESOFTARCHIVEAFA_H_
#define _PEALICESOFTARCHIVEAFA_H_

#include "PEArchive.h"

namespace pe
{

	struct PEStream;
	struct PEArchiveRaw;

	struct AliceArchiveAfaHeader
	{
		byte header[4];
		dword header_size;

		byte type[8];
		dword unknown1;
		dword unknown2;
		dword unknown3;
	};

	struct AliceArchiveAfaFileInfoHeader
	{
		byte info[4];
		dword compressed_size;
		dword uncompressed_size;
		dword files_total;
	};

	struct AliceArchiveAfaEntry
	{
		dword path_len;
		dword unknown2;
		wchar_t* path;
		dword unknown3;
		byte something[8];
		dword offset;
		dword unknown4;
	};

	struct AliceArchiveAfaFileInfo
	{
		AliceArchiveAfaFileInfoHeader* header;
		byte* data;

		AliceArchiveAfaEntry* entries;
		unsigned int entries_total;
	};

	struct AliceArchiveAfa
	{
		AliceArchiveAfaHeader* header;
		AliceArchiveAfaFileInfo* info;

		wchar_t* path;
		wchar_t* workingdir;
	};

	PE_EXPORT int AliceArchiveAfaReadHeader(AliceArchiveAfaHeader* a_Target, PEStream* a_Stream);
	PE_EXPORT int AliceArchiveAfaReadData(AliceArchiveAfa* a_Target, AliceArchiveAfaHeader* a_Header, PEStream* a_Stream);
	PE_EXPORT int AliceArchiveAfaOpenFile(PEStream* a_Target, AliceArchiveAfa* a_Archive, unsigned int a_Index);

	PE_EXPORT int AliceArchiveAfaToRaw(PEArchiveRaw* a_Target, AliceArchiveAfa* a_Archive);

	class PE_DLL_EXPORT ArchiveAliceSoftAfa : public PEArchive
	{

	public:

		ArchiveAliceSoftAfa();
		~ArchiveAliceSoftAfa();

		int LoadHeader(PEStream* a_Stream);
		int LoadBody();

	private:

		AliceArchiveAfaHeader m_Header;
		
		AliceArchiveAfaFileInfoHeader m_InfoHeader;
		AliceArchiveAfaFileInfo m_Info;
		byte* m_Data;

		AliceArchiveAfaEntry* m_Entries;
		unsigned int m_EntriesTotal;

	};

}; // namespace pe

#endif